package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author lyp
 * @date 2022/11/9 19:41
 */
@Configuration
public class GateWayConfig {
        @Bean
        public CorsWebFilter corsWebFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            CorsConfiguration configuration = new CorsConfiguration();
            configuration.addAllowedHeader("*");
            configuration.addAllowedMethod("*");
            configuration.addAllowedOrigin("*");
            // 是否允许携带cookie跨域
            configuration.setAllowCredentials(true);
            source.registerCorsConfiguration("/**", configuration);
            return new CorsWebFilter(source);
        }
}
